<?php
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
$return['status']=$this->member_status;
$return['xuelis']=$this->xuelis;
$return['fuwus']=pdo_getall('jy_ailiao_fuwu',array('uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');
$return['workers']=pdo_getall('jy_ailiao_worker',array('uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');
$return['levels']=pdo_getall('jy_ailiao_level',array('uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');
if($_RQ['op']=='list'){
	$pindex = max(1, intval($_RQ['page']));
	$psize = 15;
	$params=array('uniacid'=>$_SESSION['uniacid']);
	if(!empty($_RQ['nickname'])){
		$params['nickname like']='%'.trim($_RQ['nickname']).'%';
		$return['params']['nickname']=$_RQ['nickname'];
	}
	if(!empty($_RQ['realname'])){
		$params['realname like']='%'.trim($_RQ['realname']).'%';
		$return['params']['realname']=$_RQ['realname'];
	}
	if(!empty($_RQ['mobile'])){
		$params['mobile']=intval($_RQ['mobile']);
		$return['params']['mobile']=$_RQ['mobile'];
	}
	if(isset($_RQ['status'])){
		$params['status']=intval($_RQ['status']);
		$return['params']['status']=$_RQ['status'];
	}
    $orderby='id desc';
	$total='';
	$return['list']=pdo_getslice('jy_ailiao_member',$params,array($pindex,$psize),$total,$fields,'',$orderby);
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$current_year=date('Y');
	foreach($return['list'] as &$v){
		$v['birth']=json_decode($v['birth'],true);
		$v['age'] = $v['birth']['year']?$current_year - $v['birth']['year'] - 1:'**';
		$v['member']=array(
			'nickname'=>$v['nickname'],
			'avatar'=>$v['avatar'],
			'sex'=>$v['sex'],
		);
	}
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			array('op'=>'list','title'=>'女士管理'),
		),
		'list'=>array('data'=>'list','del_one'=>false,'delall'=>false,'list'=>array(
			array('name'=>'member','title'=>'昵称','type'=>'member'),
			array('name'=>'realname','title'=>'真实姓名','type'=>'string'),								
			array('name'=>'mobile','title'=>'电话','type'=>'string'),
			array('name'=>'age','title'=>'年龄','type'=>'string'),
			array('name'=>'xueli','title'=>'学历','type'=>'radio','options'=>'xuelis'),
			array('name'=>'city','title'=>'城市','type'=>'string'),
			array('name'=>'fuwu_id','title'=>'服务站','type'=>'select','options'=>'fuwus'),
			array('name'=>'worker_id','title'=>'关联红娘','type'=>'select','options'=>'workers'),
			array('name'=>'level_id','title'=>'等级','type'=>'select','options'=>'levels'),
			array('name'=>'status','title'=>'状态','type'=>'radio','options'=>'status'),
			array('name'=>'viptime','title'=>'VIP有效期','type'=>'time'),			
			array('name'=>'createtime','title'=>'时间','type'=>'time'),				
		),'action'=>array(
			array('type'=>'href','op'=>'setleve','title'=>'设置等级/有效期'),
		),),
		'search'=>array(
			array('name'=>'nickname','width'=>15,'title'=>'昵称','type'=>'string'),
			array('name'=>'realname','width'=>15,'title'=>'真实姓名','type'=>'string'),
			array('name'=>'mobile','width'=>15,'title'=>'电话','type'=>'string'),
			array('name'=>'status','width'=>15,'title'=>'状态','type'=>'select','options'=>'status'),
		)
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='edit'){
	$id=intval($_RQ['id']);
	if($id){
		$item=$this->get('member',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}else{
		$item=array();
	}
	$item['birth']=json_decode($item['birth'],true);
	$item['pcd']=json_decode($item['pcd'],true);
	$item['jgpcd']=json_decode($item['jgpcd'],true);
	$item['images']=json_decode($item['images'],true);
    $return['item']=$item;
	$htmls=array(
		'type'=>'edit',
		'post'=>'post',
		'desc'=>'用户设置',
		'edits'=>array(array('title'=>'基本信息','list'=>array(
			array('name'=>'nickname','title'=>'昵称','type'=>'string'),
			array('name'=>'avatar','title'=>'头像','type'=>'image'),
			array('type'=>'choose_title','title'=>'选择会员','name'=>'mid','action'=>'core/member.get_member/','choose_title'=>'选择会员',),
			array('name'=>'images','title'=>'相册','type'=>'images'),
			array('name'=>'desc','title'=>'个人签名','type'=>'text'),
			array('name'=>'realname','title'=>'真实姓名','type'=>'string'),								
			array('name'=>'mobile','title'=>'电话','type'=>'string'),
			array('name'=>'sex','title'=>'性别','type'=>'radio','options'=>'sex'),
			array('name'=>'xueli','title'=>'学历','type'=>'radio','options'=>'xuelis'),
			array('name'=>'birth','title'=>'生日','type'=>'day'),
			array('name'=>'pcd','title'=>'所在城市','type'=>'pcd'),
			array('name'=>'isjiehun','title'=>'结婚状况','type'=>'radio','options'=>'jiehuns'),
			array('name'=>'shouru','title'=>'收入状况','type'=>'radio','options'=>'shouru'),
			array('name'=>'youboy','title'=>'有没有孩子','type'=>'radio','options'=>'youboy'),
			array('name'=>'wanboy','title'=>'是否想要孩子','type'=>'radio','options'=>'wanboy'),
			array('name'=>'goufang','title'=>'购房情况','type'=>'radio','options'=>'goufang'),
			array('name'=>'gouche','title'=>'购车情况','type'=>'radio','options'=>'gouche'),
			array('name'=>'jgpcd','title'=>'籍贯','type'=>'pcd'),
			array('name'=>'weight','title'=>'体重','type'=>'radio','options'=>'weight'),
			array('name'=>'height','title'=>'身高','type'=>'radio','options'=>'height'),
			array('name'=>'tixing','title'=>'体型','type'=>'radio','options'=>'tixing'),
			array('name'=>'xiyan','title'=>'是否吸烟','type'=>'radio','options'=>'xiyan'),
			array('name'=>'hejiu','title'=>'是否喝酒','type'=>'radio','options'=>'hejiu'),
			array('name'=>'xingzuo','title'=>'星座','type'=>'radio','options'=>'xingzuo'),
			array('name'=>'minzu','title'=>'民族','type'=>'radio','options'=>'minzus'),
			array('name'=>'jh_time','title'=>'结婚时间','type'=>'radio','options'=>'jh_time'),
			array('name'=>'wechat','title'=>'微信号','type'=>'string'),
			array('name'=>'fuwu_id','title'=>'服务站','type'=>'select','options'=>'fuwus'),
			array('name'=>'worker_id','title'=>'关联红娘','type'=>'select','options'=>'workers'),		
			array('name'=>'status','title'=>'状态','type'=>'radio','options'=>'status'),
		))),
	);
	$return['years']=array();
	for($i=1918;$i<2006;$i++){
		$return['years'][]=$i;
	}
	$return['months']=array(1,2,3,4,5,6,7,8,9,10,11,12);
	$return['days']=array(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31);
	$return['sex']=$this->sex;
	$return['jiehuns']=$this->jiehuns;
	$return['shouru']=$this->shourus;
	$return['youboy']=$this->youboy;
	$return['wanboy']=$this->wanboy;
	$return['goufang']=$this->goufang;
	$return['gouche']=$this->gouche;
	$return['height']=$this->heights;
	$return['weight']=$this->weights;
	$return['tixing']=$this->tixing;
	$return['xiyan']=$this->xiyan;
	$return['hejiu']=$this->hejiu;
	$return['xingzuo']=$this->xingzuo;
	$return['jh_time']=$this->jh_time;
	$return['minzus']=$this->model('model')->minzus();
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	$data=array(
		'level_id'=>trim($postdata['level_id']),
		'mid'=>intval($postdata['mid']),
		'mobile'=>trim($postdata['mobile']),
		'nickname'=>trim($postdata['nickname']),
		'realname'=>trim($postdata['realname']),
		'desc'=>trim($postdata['desc']),
		'email'=>trim($postdata['email']),
		'avatar'=>trim($postdata['avatar']),
		'images'=>ijson_encode($postdata['images']),
		'qq'=>trim($postdata['qq']),
		'wechat'=>trim($postdata['wechat']),
		'city'=>$postdata['pcd']['city'],
		'pcd'=>ijson_encode($postdata['pcd']),
		'jgpcd'=>ijson_encode($postdata['jgpcd']),
		'address'=>trim($postdata['address']),
		'lat_lng'=>ijson_encode($postdata['lat_lng']),
		'birth'=>ijson_encode($postdata['birth']),
		'year'=>trim($postdata['birth']['year']),
		'sex'=>trim($postdata['sex']),
		'isjiehun'=>trim($postdata['isjiehun']),
		'xueli'=>trim($postdata['xueli']),
		'shouru'=>trim($postdata['shouru']),
		'youboy'=>intval($postdata['youboy']),
		'wanboy'=>trim($postdata['wanboy']),
		'goufang'=>trim($postdata['goufang']),
		'gouche'=>trim($postdata['gouche']),
		'weight'=>trim($postdata['weight']),
		'height'=>trim($postdata['height']),
		'tixing'=>trim($postdata['tixing']),
		'xiyan'=>trim($postdata['xiyan']),
		'hejiu'=>trim($postdata['hejiu']),
		'xingzuo'=>trim($postdata['xingzuo']),
		'minzu'=>trim($postdata['minzu']),
		'jh_time'=>trim($postdata['jh_time']),
		'fuwu_id'=>trim($postdata['fuwu_id']),
		'worker_id'=>trim($postdata['worker_id']),
		'status'=>trim($postdata['status']),
	);
	if(!$data['nickname']|| !$data['avatar']){
		exi('昵称头像必填！','error');
	}
	
	$id=intval($postdata['id']);
	if($id){
		$this->update('member',$data,array('id'=>$id));
		exi('设置成功！','','list');
	}else{
		$data['uniacid']=$_SESSION['uniacid'];
		$data['createtime']=time();
		$this->insert('member',$data);
		exi('添加成功！','','list');
	}
}
if($_RQ['op']=='setleve'){
	if($_RQ['postdata']){
		$post=get_postdata();
		$id=intval($post['id']);
		$update=array(
			'level_id'=>intval($post['level_id']),
			'viptime'=>strtotime($post['viptime']),
		);
		pdo_update('jy_ailiao_member',$update,array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));
		exi('设置成功！','','//list/');
	}
	$id=intval($_RQ['id']);
	$item=pdo_get('jy_ailiao_member',array('uniacid'=>$_SESSION['uniacid'],'id'=>$id),array('id','mid','level_id','viptime'));
	$item['viptime'] =$item['viptime']?date('Y/m/d H:i',$item['t_time']):'';
	$return['item']=$item;	
	$htmls=array(
		'type'=>'edit',
		'desc'=>'设置等级',
	);
	$htmls['edit']=array(
			array('type'=>'select','title'=>'等级','name'=>'level_id','options'=>'levels'),
			array('type'=>'time','title'=>'有效期','name'=>'viptime','help'=>'默认等级设置VIP有效期无效！'),
	);
	$return['htmls']=$htmls;
	exi($return);
}
?>